import store from "@/store/index.js"
import msg from "@/util/msg.js"
import api from "@/util/api.js"
import axios from "@/util/request.js"
const wechat = {
	/**
	 * 获取code
	 * @param {Object} info
	 */
	getcode() {
		return new Promise((resolve, reject) => {
			uni.getProvider({
				service: 'oauth',
				success: (type) => {
					uni.login({
						provider: type.provider[0],
						success: (e) => {
							if (e.errMsg == 'login:ok') {
								resolve({code:e.code,type:type.provider[0]})
							} else {
								msg.toast("获取失败")
								return
							}
						}
					})
				}
			})

		})
	},
	getOpenid() {
		return new Promise((resolve, reject) => {
			wechat.getcode().then((code) => {
				axios.request(api.getOpenId, "GET", {
					code: code.code,
					type:code.type
				}).then((val) => {
					resolve({openId:val.data.openId,type:code.type})
				})
			})
		})

	},

}


export default wechat